# -*- coding: utf-8 -*-
from PyQt5 import QtWidgets
from gui.stability_repeatability_test.repeatability_setting import Ui_Dialog
from PyQt5.QtGui import QIcon,QPixmap
from PyQt5.QtCore import pyqtSignal,pyqtSlot
from PyQt5.QtWidgets import QDialog,QMessageBox
from utils.color_util import color
from utils.log_util import loggings as logger


class RepeatabilityDialog(QtWidgets.QDialog, Ui_Dialog):
    dialogSignal = pyqtSignal(object, object)

    def __init__(self):
        super().__init__()
        self.setupUi(self)
        icon = QIcon()
        icon.addPixmap(
            QPixmap("icons/logo.ico"),
            QIcon.Normal,
            QIcon.Off)
        self.setWindowIcon(icon)


    @pyqtSlot()
    def on_btnEnsure_clicked(self):
        try:
            duration = self.cbb_duration_para.currentText().strip()
            interval = self.cbb_interval.currentText().strip()
            if duration is not None and interval is not None:
                self.dialogSignal.emit(duration, interval)
                self.close()
            else:
                self.show_notification("提示", "查询条件不能为空")
        except Exception as e:
            logger.error("on_btnEnsure_clicked," + str(e))

    def show_notification(self, title, content):
        QMessageBox.information(self, title, content, QMessageBox.Yes, QMessageBox.Yes)

    @pyqtSlot()
    def on_btnCancel_clicked(self):
        self.close()
